package org.blogwu.learn.multithread.chapter3.demo12;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MainV2 extends Thread {

    private String name;

    public MainV2(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(System.currentTimeMillis() + "  " + name + " start");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(3);
        ThreadPoolExecutor th = new ThreadPoolExecutor(1, 5, 5, TimeUnit.SECONDS, arrayBlockingQueue);
        // 缓存队列最多只能装100 ,线程次装20个,,,总共最多120个, 如果超过这个数量,这会执行拒绝策略,默认是抛出异常,阻止程序继续执行.
        for (int i = 0; i < 8; i++) {
            th.submit(new MainV2("线程" + i));
        }
        Thread.sleep(10000);
        System.out.println("hello");
    }


}
